//
//  ViewController.m
//  定位WhereAmI
//
//  Created by student on 16/4/1.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"


#import <CoreLocation/CoreLocation.h>

#import <MapKit/MapKit.h>

#import "place.h"
@interface ViewController ()<CLLocationManagerDelegate,MKMapViewDelegate>
{
    CLLocation *lastLocation;
}
//经度
@property (weak, nonatomic) IBOutlet UILabel *longitudeLabel;
//纬度
@property (weak, nonatomic) IBOutlet UILabel *latitudeLabel;


//位置管理器
@property (nonatomic,strong) CLLocationManager *locationManager;
@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)btnPressed:(id)sender
{
    self.locationManager = [[CLLocationManager alloc] init];
    
    //精度
    self.locationManager.delegate = self;
    //更新距离
    self.locationManager.distanceFilter = 5  0.0f;//在一百米范围内移动 不会刷新位置
    //请求用户权限
    [self.locationManager requestWhenInUseAuthorization];
    //启用定位
    [self.locationManager startUpdatingLocation];
    
}

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(nonnull CLLocation *)newLocation
           fromLocation:(nonnull CLLocation *)oldLocation
{
    // 将得到的经纬显示到界面
    self.longitudeLabel.text = [NSString stringWithFormat:@"%.5f",newLocation.coordinate.longitude];
    
    self.latitudeLabel.text = [NSString stringWithFormat:@"%.5f",newLocation.coordinate.latitude];
    
    
    //关闭更新
    [self.locationManager stopUpdatingLocation];
    
    
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations
{
    
}









@end
